package fr.nts.framework.front.form.validation;

import java.io.Serializable;
import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.google.common.collect.Maps;

import fr.nts.framework.front.form.AbstractForm;

/**
 * Représente le résultat d'une validation NTS sur un formulaire complet
 * 
 * @author sco
 * @version 1.0.0
 */
public class FormValidationResult implements Serializable{

	private static final long serialVersionUID = 1L;

	/**
	 * Le formulaire associé
	 */
	private AbstractForm form;
	
	/**
	 * Le résultat de validation
	 */
	private Map<String, FieldValidationResult> errorFields = Maps.newHashMap();

	
	public FormValidationResult(AbstractForm form){
		this.form = form;
	}
	
	
	/**
	 * @return Retourne le résultat de la validation
	 */
	public boolean isValid(){
		return errorFields.size() == 0;
	}
	
	
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString(){
		return new ToStringBuilder(this).append("form", form == null? null: form.toString())
		                                .append("Nb errorField", errorFields.size())
		                                .toString();
	}
	
	
	// GETTER / SETTER
	public Map<String, FieldValidationResult> getErrorFields(){
		return errorFields;
	}

	public void setErrorFields(Map<String, FieldValidationResult> errorFields){
		this.errorFields = errorFields;
	}

	public AbstractForm getForm(){
		return form;
	}

	public void setForm(AbstractForm form){
		this.form = form;
	}
}